import spock.lang.Specification

/**
 * 一个元素的栈
 * Created by houjinxin on 17-3-31.
 */
class StackWithOneElementSpec extends Specification {

    def stack = new Stack();

    def setup(){
        stack.push('test')
    }

    def "size"() {
        expect: stack.size() == 1
    }

    def "pop"() {
        when:
            def x = stack.pop()
        then:
            x == 'test'
            stack.size() == 0
    }

    def "peek"() {
        when:
            def x = stack.peek()
        then:
            x == 'test'
            stack.size() == 1
    }

    def "push"(){
        when:
            stack.push("test1")
        then:
            stack.size() == 2
            stack.peek() == 'test1'
    }
}
